package com.example.demo.job;

import com.example.demo.service.EbookSnapshotService;
import com.example.demo.util.SnowFlake;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class EbookSnapshotJob {
    private  static  final Logger LOG= (Logger) LoggerFactory.getLogger(EbookSnapshotJob.class);

    @Resource
    private SnowFlake snowFlake;

    @Resource
    private EbookSnapshotService ebookSnapshotService;

    /**
     *滴定仪cron表达式跑批
     * 只有等上一次执行完成，下一次才会在下一时间点执行，错过就错过
     * */
    @Scheduled(cron = "0/5 * * * * ?")
    public  void  doSnapshot(){
        //增加日志流水号
        MDC.put("LOG_ID",String.valueOf(snowFlake.nextId()));
        Long start=System.currentTimeMillis();
        ebookSnapshotService.genSnapshot();
        LOG.info("生成今日电子书快照结束，耗时：{}毫秒",System.currentTimeMillis()-start);
    }
}
